#include <iostream>
#include <iomanip>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <string>

using namespace std;

typedef struct TACCOUNT {
	int id;
	char name[40];
} TACCOUNT;

typedef struct TRECORD {
	int tranId;
	int accNo;
	int amount;
} TRECORD;

istream& operator >> (istream& in, TACCOUNT& x) {
	char line[40];
	memset(line, 0, 40);
	in.getline(line, 40);
	strcpy(x.name, &line[3]);
	line[3] = 0;
	x.id = atoi(line);
	return in;
}
istream& operator >> (istream& in, TRECORD& x) {
	char line[20];
	memset(line, 0, 20);
	in.getline(line, 20);
	x.amount = atoi(&line[6]);
	line[6] = 0;
	x.accNo = atoi(&line[3]);
	line[3] = 0;
	x.tranId = atoi(line);
	return in;
}

vector<TACCOUNT> accounts;
vector<TRECORD> records;

string getName(int no) {
	for (vector<TACCOUNT>::iterator it=accounts.begin(); it!=accounts.end();++it)
		if ((*it).id == no) return (*it).name;
	return "";
}

int main(void)
{
	while (true) {
		TACCOUNT acc;
		cin >> acc;
		if (acc.id == 0) break;
		accounts.push_back(acc);
	}
	int thisTran = -1;
	int tot = 0;
	while (true) {
		TRECORD rec;
		cin >> rec;
		if (rec.tranId == 0) break;
		if (thisTran == -1) {
			thisTran = rec.tranId;
		}
		if (rec.tranId != thisTran) {

			if (tot != 0) {
				cout << "*** Transaction "  
					<< setw(3) << right << setfill('0') << thisTran 
					<< " is out of balance ***" << endl;
				for (unsigned int i=0; i<records.size(); ++i) {
					cout << setw(3) << right << setfill('0') << records[i].accNo << " "
						<< setw(30) << left << setfill(' ') << getName(records[i].accNo) << " "
						<< setw(10) << right << setprecision (2) << fixed << records[i].amount/100.0 << endl;
				}
				cout << "999 Out of Balance                 " 
					<< setw(10) << right << setprecision (2) << fixed << -tot/100.0 << endl << endl;
			}
			

			tot = 0;
			records.clear();
			records.push_back(rec);
			thisTran = rec.tranId;
			tot += rec.amount;

		}
		else {
			records.push_back(rec);
			tot += rec.amount;
		}

	}

	return 0;
}